import { NextResponse } from "next/server";
import { headers, cookies } from "next/headers";
import { NextRequest } from "next/server";
// export const dynamic = "force-static"; // GET缓存
// export const revalidate = 60  // 增量静态再生（ISR）重新验证缓存的数据：
export async function GET(req: NextRequest) {
    const res = await fetch("https://qqlykm.cn/api/weather/get", {
        headers: new Headers({
            // "Content-Type": "application/json",
            // "API-Key": process.env.DATA_API_KEY,
        }),
    });
    // const res = await fetch("http://127.0.0.1:8088/api/user/1", {
    //     headers: new Headers({
    //         // "Content-Type": "application/json",
    //         // "API-Key": process.env.DATA_API_KEY,
    //     }),
    // });
    const headersList = await headers();
    const cookieStore = await cookies();
    const token = cookieStore.get("token");
    const data = await res.json();
    // return NextResponse.json({ data });
    return new NextResponse(JSON.stringify(data), {
        status: 200,
        headers: { "Set-Cookie": `token=${token?.value}` },
    });
}

export const POST = async (req: NextRequest) => {
    const res = await req.json();
    return NextResponse.json(res);
};

export async function HEAD(request: Request) {}

export async function PUT(request: Request) {}

export async function DELETE(request: Request) {}

export async function PATCH(request: Request) {}

// If `OPTIONS` is not defined, Next.js will automatically implement `OPTIONS` and set the appropriate Response `Allow` header depending on the other methods defined in the Route Handler.
export async function OPTIONS(request: Request) {}
